// 处理业务逻辑中间件
const path = require('path')
const getFile = require('../utils/file_utils')
module.exports = async (ctx, next) => {
    const url = ctx.request.url
    let filePath = url.replace('/api','')
    filePath = '../data' + filePath + '.json'
    filePath = path.join(__dirname,filePath)
    try{
        const ret = await getFile.getFileJsonData(filePath)
        ctx.response.body = ret
    }catch(error){
        const errMsg = {
            message: '文件不存在',
            status: 404
        }
        ctx.response.body = JSON.stringify(errMsg)
    }
    await next()
}